<?php
/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 *
 */
$styleSheet = "orange";

$GLOBALS['lang_Common_SortAscending'] = $lang_Common_SortAscending;
$GLOBALS['lang_Common_SortDescending'] = $lang_Common_SortDescending;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../../themes/<?php echo $styleSheet; ?>/css/style.css" rel="stylesheet" type="text/css"/>
<!--[if lte IE 6]>
<link href="../../themes/<?php echo $styleSheet; ?>/css/IE6_style.css" rel="stylesheet" type="text/css"/>
<![endif]-->
<!--[if IE]>
<link href="../../themes/<?php echo $styleSheet; ?>/css/IE_style.css" rel="stylesheet" type="text/css"/>
<![endif]-->
<script type="text/javascript" src="../../themes/<?php echo $styleSheet;?>/scripts/style.js"></script>
<link type="text/css" rel="stylesheet" href="/themes/orange/css/yui/calendar/assets/calendar.css" />
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="../../scripts/octopus.js"></script>
<script type="text/javascript" src="../../scripts/common.js"></script>
<script type="text/javascript" src="../../scripts/jquery/jquery.js"></script>
<script type="text/javascript" src="../../scripts/yui/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="../../scripts/yui/event/event-min.js" ></script>
<script type="text/javascript" src="../../scripts/yui/dom/dom-min.js" ></script>

<script type="text/javascript" src="../../scripts/yui/container/container-min.js"></script>
<script type="text/javascript" src="../../scripts/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="../../scripts/yui/element/element-beta-min.js"></script>

<script type="text/javascript" src="../../scripts/yui/calendar/calendar.js"></script>
<script type="text/javascript" src="../../scripts/yui/button/button-beta-min.js"></script>

<script type="text/javascript" src="../../scripts/yui/animation/animation-min.js"></script>
<script type="text/javascript" src="../../scripts/yui/autocomplete/autocomplete-min.js"></script>
<script type="text/javascript" src="../../scripts/time.js"></script>

<script type="text/javascript" src="../../scripts/calendar/calendar.js"></script>
<script type="text/javascript">
YAHOO.namespace("OrangeHRM.time");

YAHOO.OrangeHRM.calendar.format = 'yyyy-MM-dd';
YAHOO.OrangeHRM.calendar.formatHint.format = '';
YAHOO.OrangeHRM.time.format = 'HH:mm';
function add() {
	document.standardView.submit();
}
function clear_form() {
	document.standardView.loc_code.options[0].selected=true;
	document.standardView.loc_name.value='';
}
YAHOO.OrangeHRM.container.init();

function GetDateDiff(startTime, endTime,diffType) {
    //将xxxx-xx-xx的时间格式，转换为 xxxx/xx/xx的格式
    startTime = startTime.replace(/\-/g, "/");
    endTime = endTime.replace(/\-/g, "/");
    //将计算间隔类性字符转换为小写
    diffType = diffType.toLowerCase();
    var sTime = new Date(startTime);      //开始时间
    var eTime = new Date(endTime);  //结束时间
    //作为除数的数字

    return parseInt((eTime.getTime() - sTime.getTime()) / 1000 );
}

function formcheck(){
	var EmpName = document.getElementById('EmpName').value;
	var Content = document.getElementById('Content').value;
	var StartTime = document.getElementById('StartTime').value;
	var EndTime = document.getElementById('EndTime').value;
	var holiday = parseFloat(document.getElementById('holiday').innerHTML);
	var hour = document.getElementById('hour').value;
	var obj = document.getElementById('AdType');
      var type = obj.options[obj.selectedIndex].value;
	var shourobj = document.getElementById("StartTime_hour");
	var shour = shourobj.options[shourobj.selectedIndex].value;
	var sminobj = document.getElementById("StartTime_min");
	var smin = sminobj.options[sminobj.selectedIndex].value;
	var ehourobj = document.getElementById("EndTime_hour");
	var ehour = ehourobj.options[ehourobj.selectedIndex].value;
	var eminobj = document.getElementById("EndTime_min");
	var emin = eminobj.options[eminobj.selectedIndex].value;

	var sdate = StartTime+ " "+shour+":"+smin+":00";
	var edate = EndTime+ " "+ehour+":"+emin+":00";
	
	if(EmpName == ''){
		alert("员工名字不能为空，你请确认是员工");
		return false;
	}
	if(Content == ''){
		alert("申请原因不能为空");
		return false;
	}
	if(StartTime == ''){
		alert("开始不能为空");
		return false;
	}
	if(EndTime == ''){
		alert("结束时间不能为空");
		return false;
	}

	if(GetDateDiff(sdate, edate,"second") < 0){
		alert("结束时间不能小于开始时间");
		return false;
	}
	
	if(hour == ''){
		alert("时长不能为空");
		return false;
	}
	
	//判断年假是否足够
	if(type == 3){
		if(holiday == 0){
			alert("抱歉，你的年假已经用完或超过有效期了！");
			return false;
		}else if(holiday < hour){
			alert("抱歉，你的年假不够本次请假的小时数！");
			return false;
		}
	}
	
}

</script>
<style>
.shownameclass{float:left;width:370px;height:150px;position: absolute;z-index:5000;background-color:#ffffff;left:70px;border:1px solid #ccc;overflow:auto;}
</style>
<body class="yui-skin-sam">

<div class="formpage2col">
<form name="standardView" id="standardView" method="post" action="<?php echo $_SERVER['PHP_SELF']?>?adcode=report&action=My&s=save" onsubmit="return formcheck()">
	<div class="outerbox">
		<div class="mainHeading"><h2>添加特殊考勤</h2></div>
		<div style="padding:10px;font-size:14px;line-height:22px;">你的年假剩余小时数：<font color=red><span id="holiday"><?php echo $records['ResidualHours']['jiaqi'];?></span></font>小时,还有年假<font color=red><?php echo $records['ResidualHours']['FreezeHour'];?></font>小时在审批中；有效期：
		<?php echo $records['ResidualHours']['EffectDate']."~".$records['ResidualHours']['EndDate'];?></div>
		<input type="hidden" name="Id" id="Id" value="<?php echo isset($records['Id']) ? $records['Id']:'';?>" />
		<input type="hidden" name="EmpId" id="EmpId" value="<?php echo isset($records['emp_number']) ? $records['emp_number']:'';?>" />

		<label for="txtEmpLastName">员工名字 <span class="required">(不可修改)</span></label>
		<input type="text" name="EmpName" id="EmpName" class="formInputText" 
			value="<?php echo isset($records['emp_name']) ? $records['emp_name']:'';?>" readonly/><br>
		<div id="ShowEmpName" class="shownameclass" style="display:none"><table id="tbname" width="350" border="0" cellspacing="0" cellpadding="0"></table></div>
		<br class="clear" />
		
		<label for="txtAdType" id="txtAdType">考勤类型 <span class="required">*</span></label>
		<select name="AdType" id="AdType" class="formSelect"> 
			<?php foreach ($records['typelist'] as $key => $val) {?>
			<option value="<?php echo $key;?>" <?php if($records['TypeId'] == $key) echo "selected";?>><?php echo $val;?></option>
			<?php } ?>
		</select>
		<br class="clear" />
		<label for="txtEmpFirstName" id="txtEmpFirstName">申请原因 <span class="required">*</span></label>
		<textarea name="Content" id="Content" class="formInputText" style="margin-left:10px;width:270px;height:100px;"/><?php echo isset($records['Content']) ? $records['Content']:'';?></textarea>
        <br class="clear" />
		<label for="txtEmpFirstName" id="txtEmpFirstName">开始时间 <span class="required">*</span></label>
		<input type="text" name="StartTime" id="StartTime" class="formInputText" 
			value="<?php echo isset($records['StartTime']) ? @date('Y-m-d',$records['StartTime']):@date('Y-m-d');?>"/>
			<input type="button" class="calendarBtn" value="" name="Submit">
            <select id="StartTime_hour" name="StartTime_hour" class="formSelect" style="width:50px;">
            <?PHP 
			for($i=0;$i<24;$i++){
				echo "<option value=\"".$i."\">".$i."时</option>";
			}
			?>
            </select>
            <select id="StartTime_min" name="StartTime_min" class="formSelect" style="width:50px;">
            <?PHP 
			for($j=0;$j<61;$j++){
				if($j % 5 ==0){
					echo "<option value=\"".$j."\">".$j."分</option>";
				}
			}
			?>
            </select>
		<br class="clear" />

		<label for="txtEmpMiddleName">结束时间<span class="required">*</span></label>
		<input type="text" name="EndTime" id="EndTime" class="formInputText"  value="<?php echo isset($records['EndTime']) ? @date('Y-m-d',$records['EndTime']):'';?>"/>
		<input type="button" class="calendarBtn" value="" name="Submit">
        <select id="EndTime_hour" name="EndTime_hour" class="formSelect" style="width:50px;">
            <?PHP 
			for($i=0;$i<24;$i++){
				echo "<option value=\"".$i."\">".$i."时</option>";
			}
			?>
            </select>
            
            <select id="EndTime_min" name="EndTime_min" class="formSelect" style="width:50px;">
            <?PHP 
			for($j=0;$j<61;$j++){
				if($j % 5 ==0){
					echo "<option value=\"".$j."\">".$j."分</option>";
				}
			}
			?>
            </select>
            
		<br class="clear"/>
        <label for="txtEmpMiddleName">时长（小时）：<span class="required">*</span></label>
		<input type="text" name="hour" id="hour" class="formInputText"  value="<?php echo $records['hour'];?>"/>
        <span style="line-height:32px;">小时</span>
        <br class="clear"/>
		<?php  if(isset($records['Id']) && $records['Id'] > 0) { ?>
		<label for="txtEmpMiddleName">添加时间</label>
		<?php echo isset($records['AddTime']) ? @date('Y-m-d',$records['AddTime']):'';?>
		<br class="clear"/>
		<?php } ?>
        <div style="padding:2px 5px;line-height:20px;color:#F00;">提示：
        <br class="clear"/>1、时长填写为你的总小时数，一天为8个小时，多少天填写天数×8小时,如2天为2×8=16小时，即时长为16小时；
        <br class="clear"/>2、一天的开始时间是上班时间，结束时间是下班时间，多天的为第一天的上班时间到最后一天下班时间；
        <br class="clear"/>3、年假审批通过才会扣除，一天为8小时,申请后暂时冻结申请的小时数。</div>
		<br class="clear"/>
        <div class="formbuttons">
			<input type="submit" class="savebutton" id="btnEdit" onmouseover="moverButton(this);" onmouseout="moutButton(this);"
				value="<?php echo $lang_Common_Save;?>" title="<?php echo $lang_Common_Save;?>" />
			<input type="button" class="resetbutton" onclick="document.GoodsRecord.reset(); return false;"
				onmouseover="moverButton(this);" onmouseout="moutButton(this);"
				 value="<?php echo $lang_Common_Reset;?>" />
        </div>
	</div>
	<div class="requirednotice"><?php echo preg_replace('/#star/', '<span class="required">*</span>', $lang_Commn_RequiredFieldMark); ?>.</div>
	</form>
</div>
<div id="cal1Container" style="position:absolute;" ></div>
<script type="text/javascript">
//<![CDATA[
    if (document.getElementById && document.createElement) {
        roundBorder('outerbox');
    }
//]]>
</script>
</body>
